/* vim: set expandtab shiftwidth=4: -*- mode: c++; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: nil -*-
EasyForms
An easy-to-use program for completing scanned documents.
Copyright (C) 2006-2007 Wesley Crossman
Email: wesley@crossmans.net

You can redistribute and/or modify this software under the terms of the GNU
General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA */

#ifndef ZOOM_DOCUMENT_SCENE_H
#define ZOOM_DOCUMENT_SCENE_H

#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsSvgItem>
#include <QTextStream>
#include <QDomDocument>
#include <QDomElement>

class FormsDocumentGraphicsItem;
class QSvgRenderer;
class QGraphicsLineItem;

class FormsDocumentScene : public QGraphicsScene {
Q_OBJECT
public:
    enum Type {CheckBox, TextBox};
    static Type selected;
    FormsDocumentScene(QObject *parent, const QPixmap &pixmap = QPixmap());
    void read(const QString &xml);
    void write(QTextStream &stream);
    void writeImage(QIODevice *stream);
protected:
    FormsDocumentGraphicsItem *document;
};

class FormsDocumentGraphicsItem : public QGraphicsPixmapItem {
public:
    FormsDocumentGraphicsItem();
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *);
};

class FormsItem {
public:
    enum Mode {Design, Delete, Edit, Print};
    static void setMode(Mode mode, QGraphicsScene *scene);
    static Mode getMode();
    FormsItem();
    virtual ~FormsItem();
    virtual void move(QPointF pos) = 0;
    virtual QDomElement toElement(QDomDocument &doc) = 0;
protected:
    virtual void setToMode() = 0;
};

class FormsCheckBox : public QObject, public QGraphicsRectItem, public FormsItem {
Q_OBJECT
public:
    static qreal defaultSize;
    FormsCheckBox();
    void move(QPointF pos);
    void setScale(qreal value);
    static FormsCheckBox *fromElement(QDomElement &e);
    QDomElement toElement(QDomDocument &doc);
protected:
    QGraphicsLineItem *slash, *backslash;
    qreal scaleValue;
    bool checked;
    void hoverEnterEvent(QGraphicsSceneHoverEvent *);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
    void mousePressEvent(QGraphicsSceneMouseEvent *);
    void setChecked(bool checked);
    void setToMode();
    void setVisualStatus(bool value);
};

class FormsMoveItem;

class FormsTextItem : public QGraphicsTextItem, public FormsItem {
Q_OBJECT
public:
    static QFont defaultFont;
    QList < FormsMoveItem * > handles;
    FormsTextItem(const QString &text);
    void move(QPointF pos);
    static FormsTextItem *fromElement(QDomElement &e);
    QDomElement toElement(QDomDocument &doc);
public slots:
    void updateForNewSize();
protected:
    QGraphicsRectItem *border;
    FormsMoveItem *tlHandle, *trHandle, *blHandle, *brHandle;
    void hoverEnterEvent(QGraphicsSceneHoverEvent *);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
    void mousePressEvent(QGraphicsSceneMouseEvent *);
    void setVisualStatus(bool value);
    void setToMode();
};

#endif

